<template>
  <Card title="科室管理 - 编辑">
    <Card :bordered="false">
      <Button type="primary" @click="showAdd" >添加</Button>
    </Card>
    <Table width="550" border stripe ref="selection" size="small" :columns="columns" :data="nowData">
      <template slot-scope="{ row, index }" slot="action">
        <Button type="primary" size="small" style="margin-right: 5px" @click="showAll(row)">编辑</Button>
        <Button type="error" size="small" @click="remove(row)">删除</Button>
        <Modal title="编辑" v-model="visible" class-name="fl-image-modal"   @on-ok="okEnd">
          <Form :model="cuHeritageCategory" :label-width="80" style="width: 60vw">
            <FormItem label="跳转链接" style="width:300px">
              <Input v-model="cuHeritageCategory.cuHeritageCategoryName" placeholder="请输入名称"></Input>
            </FormItem>
          </Form>
            <div class="demo-upload-list" v-if="hasImage">
              <img :src="imgUrl"  />
              <div class="demo-upload-list-cover">
                <!--            <Icon type="ios-eye-outline" @click.native="handleView(imgUrl)"></Icon>-->
                <Icon type="ios-trash-outline" @click.native="handleRemove()"></Icon>
              </div>
            </div>
            <Upload
              :action="actionUrl"
              :format="['jpg','jpeg','png']"
              :max-size="2048"
              :on-exceeded-size="handleMaxSize"
              :on-success="handleSuccess"
              :show-upload-list="false"
              style=" width:58px;">
              <Button icon="ios-cloud-upload-outline" v-if="imgUrl ==''?true:false">上传图片</Button>
            </Upload>

        </Modal>
        <Modal
          v-model="modal1"
          title="提示"
          @on-ok="okDel"
          @on-cancel="cancel">
          <p>确定要删除此新闻吗?删除后将不能恢复</p>
        </Modal>
      </template>
    </Table>
    <Page :total="dataCount" :page-size="pagingCondition.size" @on-change="changePage"
          @on-page-size-change="_nowPageSize"
          show-total show-sizer show-elevator/>
  </Card>
</template>

<script>
export default {
  name: 'heritage-category.vue',
  data () {
    return {
      actionUrl: this.$all.baseUploadURL + '/me-minio/uploadImages',
      hasImage: false,
      imgUrl: '',
      visible: false,
      delRow: {},
      cuHeritageCategory: {
        cuHeritageCategoryId: null,
        cuHeritageCategoryName: '',
        cuHeritageCategoryImages: ''
      },
      dataCount: 0,
      pagingCondition: {
        size: 10,
        current: 1
      },
      modal1: false,
      columns: [
        {
          title: '序号',
          key: 'cuHeritageCategoryId'
        },
        {
          title: '昵称',
          key: 'cuHeritageCategoryName'
        },
        {
          title: '操作',
          slot: 'action',
          width: 150,
          align: 'center'
        }
      ],
      nowData: []

    }
  },
  methods: {

    handleRemove () {
      this.imgUrl = ''
      this.hasImage = false
    },
    showAdd () {
      this.cuHeritageCategory = {
        cuHeritageCategoryName: '',
        cuHeritageCategoryImages: ''
      }
      let _this = this
      _this.imgUrl = this.cuHeritageCategory.cuHeritageCategoryImages
      _this.visible = true
    },
    showAll (row) {
      this.cuHeritageCategory = row
      let _this = this
      _this.hasImage = true
      _this.imgUrl = this.cuHeritageCategory.cuHeritageCategoryImages
      _this.visible = true
    },

    handleSuccess (res, file) {
      this.imgUrl = res
      this.hasImage = true
    },
    handleMaxSize (file) {
      this.$Notice.warning({
        title: '图片大小限制',
        desc: '文件 ' + file.name + '太大,不能超过 2M.'
      })
    },
    okEnd () {
      this.cuHeritageCategory.cuHeritageCategoryImages = this.imgUrl
      let url = 'saveOne'
      if (this.cuHeritageCategory.cuHeritageCategoryId) {
        url = 'updateOne'
      }
      this.$axios_supermall.post('/cu-heritage-category/' + url, this.cuHeritageCategory).then(resp => {
        if (resp.data.code == 0) {
          this.$Message.success('处理成功')
          this.query()
        } else if (resp.data.code == 101) {
          this.$Message.error(resp.data.msg)
        }
      })
    },
    okDel () {
      this.$axios_supermall.post('/cu-heritage-category/deleteId', this.delRow.cuHeritageCategoryId).then(resp => {
        if (resp.data.code == 0) {
          this.$Message.info('删除成功')
          this.query()
        } else {
          this.$Message.info(resp.data.msg)
        }
      })
    },
    remove (row) {
      this.delRow = row
      this.modal1 = true
    },
    cancel () {
      this.$Message.info('取消删除')
    },
    show (row) {
      this.cuHeritageCategory = row
      let url = 'updateOne'
      if (this.cuHeritageCategory.cuHeritageCategoryName == undefined) {
        url = 'saveOne'
      }

      let dateRow = null

      // this.$Modal.confirm({
      //   title: '编辑',
      //   onOk:async ()=>{
      //     if (this.cuHeritageCategory.cuHeritageCategoryName == '')
      //     {
      //       this.$Message.error("名称不能为空");
      //       return;
      //     }
      //     this.cuHeritageCategory.cuHeritageCategoryName = dateRow;
      //
      //     this.$axios_supermall.post("/cu-heritage-category/"+url,this.cuHeritageCategory).then(resp =>{
      //       if (resp.data.code == 0){
      //         this.$Message.success(resp.data.msg)
      //       }else {
      //         this.$Message.error(resp.data.msg);
      //       }
      //       this.query();
      //     })
      //   },
      //
      //
      // })
    },

    changePage (index) {
      this.pagingCondition.current = index
      this.query()
    },
    _nowPageSize (index) {
      // 实时获取当前需要显示的条数
      this.pagingCondition.size = index
    },
    query () {
      this.$Loading.start()
      this.$axios_supermall.post('/cu-heritage-category/queryPage', this.pagingCondition).then(resp => {
        if (resp.data.code == 0) {
          let data = resp.data.data
          this.nowData = data.records
          this.pagingCondition.current = data.current
          this.pagingCondition.size = data.size
          this.dataCount = data.total
        }
        this.$Loading.finish()
      }).catch(() => {
        this.$Loading.error()
      })
    }
  },
  mounted () {
    this.query()
  }
}
</script>

<style scoped>

</style>
